<template>
	<view class="container">
		<view class="m-title">
			收件信息<text @click="copy">点击复制</text>
		</view>
		<view class="main">
			<view class="p">
				<text>收件人</text>{{receive.receive_name}}
			</view>
			<view class="p">
				<text>联系电话</text>{{receive.receive_mobile}}
			</view>
			<view class="p">
				<text>收件地址</text>{{receive.receive_address}}
			</view>
		</view>
		<view class="m-title">
			商品信息
		</view>
		<view class="list-goods">
			<view class="item u-flex u-col-top u-row-between" v-for="(item,index) in list" :key="index">
				<view class="img">
					<image :src="http + item.image" mode="aspectFill"></image>
				</view>
				<view class="con">
					<view class="title u-line-1">
						{{item.title}}
					</view>
					<view class="tips mt20">
						<text v-for="(item3,index3) in item.spec.split(',')">{{item3}}</text>
					</view>
				</view>
				<view class="r">
					<view class="price">
						{{item.price}}元
					</view>
					<view class="num">
						×{{item.num}}
					</view>
				</view>
			</view>
			<view class="total">
				<text>商品金额：¥{{data.order_price}}</text>
				<text>服务费：¥{{data.deduct_price}}</text>
				<text>订单合计：¥{{data.total_price}}</text>
			</view>
		</view>
		<view class="m-title">
			寄出快递
		</view>
		<view class="list-express u-flex u-col-center u-row-between">
			<view class="item" :class="{on:eindex == index}" v-for="(item,index) in elist" :key="index"
				@click="change(item,index)">
				<image :src="http + item.image" mode="aspectFill"></image>
			</view>
		</view>
		<view class="m-title">
			寄出快递单号
		</view>
		<view class="kd u-flex u-col-center u-row-between">
			<view class="l">
				<input type="text" v-model="kd" placeholder="请输入快递单号">
			</view>
			<view class="r" @click="scan">
				<uni-icons type="scan" size="20" color="#666"></uni-icons>
			</view>
		</view>

		<view class="footer">
			<view class="btn" @click="send">
				发送快递
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				kd: '',
				name: "",
				alplay: "",
				orders: "",
				notes: "",
				content: ``,
				ss2: ['', '待审核', '待寄出', '待验货', '待打款', '已完成', '已关闭', '已归档'], //1=待审核,2=待寄出,3=待验货,4=待打款,5=已完成,6=已关闭,7=已归档
				http: this.$imgUrl,
				id: "",
				data: {
					order_no: ''
				},
				list: [],
				receive: {
					receive_address: "",
					receive_mobile: "",
					receive_name: '',

				},
				elist: [],
				eindex: 0,
				ename: ''
			}
		},
		onLoad(o) {
			my.setNavigationBar({
			  frontColor: '#000',
			  backgroundColor: '#fff',
			})
			this.id = o.id
			this.getData()
			this.getList()
		},
		methods: {
			scan(){
				uni.scanCode({
					success:  (res)=> {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						if(res.scanType == 'BAR'){
							this.kd = res.result
						}else{
							uni.showToast({
								title: '不能识别请重试',
								icon: "none"
							});
							return
						}
					},
					fail:() =>{
						uni.showToast({
							title: '识别失败',
							icon: "none"
						});
						return
					},
				});
			},
			change(item, index) {
				this.eindex = index
				this.ename = item.name
			},
			send() {
				if (!this.kd) {
					uni.showToast({
						title: '请填写快递单号',
						icon: "none"
					});
					return
				}
				uni.showModal({
					title: '温馨提示',
					content: '确定要发货吗?',
					success: (res) => {
						if (res.confirm) {
							console.log('用户点击确定');
							this.$http.post('/api/order/send_order', {
								id:this.id,
								express_name: this.ename,
								express_no: this.kd
							}).then(res => {
								if (res.code == 1) {
									uni.showToast({
										title: res.msg,
										icon: "none"
									});
									setTimeout(() => {
										uni.navigateBack({
											delta: 1
										})
									}, 1500)

								} else {
									uni.showToast({
										title: res.msg,
										icon: "none"
									});
								}
							}).catch(err => {
								console.log('错误信息：', err);
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});


			},
			copy() {
				let data = `${this.receive.receive_name}  ${this.receive.receive_mobile}  ${this.receive.receive_address}`
				uni.setClipboardData({
					data: data,
					success: () => {
						console.log('success');
						uni.showToast({
							title: '已复制',
							icon: "none"
						});
					}
				});
			},
			getList() {
				this.$http.post('/api/index/express', {

				}).then(res => {
					if (res.code == 1) {

						this.elist = res.data
						this.ename = this.elist[0].name

					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						});
					}
				}).catch(err => {
					console.log('错误信息：', err);
				})
			},
			getData() {
				this.$http.post('/api/order/detail', {
					id: this.id
				}).then(res => {
					if (res.code == 1) {

						this.data = res.data
						this.list = res.data.products
						this.receive = res.data.receive
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						});
					}
				}).catch(err => {
					console.log('错误信息：', err);
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	@color: #E31D21;

	.container {
		padding: 30rpx 30rpx 150rpx;

		.footer {
			position: fixed;
			background-color: #fff;
			left: 0;
			right: 0;
			padding: 20rpx 30rpx;
			z-index: 999;
			bottom: 0;

			.btn {
				width: 100%;
				height: 80rpx;
				text-align: center;
				border-radius: 40rpx;
				line-height: 80rpx;
				font-size: 32rpx;
				font-weight: 600;
				color: #fff;
				background-color: @color;
			}
		}

		.kd {
			background-color: #fff;
			padding: 20rpx;
			border-radius: 10rpx;

			.l {
				flex: 1;
				width: 1rpx;
				margin-right: 20rpx;

				input {
					font-size: 28rpx;
					color: #333;
					height: 60rpx;
					line-height: 60rpx;
				}
			}

			.r {}
		}

		.list-express {
			background-color: #fff;
			padding: 20rpx 20rpx 0;
			border-radius: 10rpx;
			flex-wrap: wrap;

			.item {
				margin: 0 15rpx 20rpx 0;
				width: 110rpx;
				height: 80rpx;
				border: 2rpx solid #fff;

				&:nth-child(5n) {
					margin-right: 0;
				}

				image {
					width: 100%;
					height: 100%;
				}

			}

			.on {
				border: 2rpx solid @color;
			}
		}

		.body {
			background-color: #fff;
			padding: 20rpx;
			border-radius: 10rpx;
		}

		.textarea {
			background-color: #fff;
			padding: 20rpx;
			border-radius: 10rpx;

			textarea {
				width: 100%;
				height: 100rpx;
				font-size: 28rpx;
				color: #333;
			}
		}

		.list {
			background-color: #fff;
			padding: 20rpx;
			border-radius: 10rpx;

			.item {
				padding: 10rpx 0;

				.l {
					width: 160rpx;
					font-size: 26rpx;
					color: #333;
				}

				.r {
					flex: 1;
					width: 1rpx;
					margin-left: 20rpx;

					input {
						font-size: 28rpx;
						color: #333;
						height: 60rpx;
						line-height: 60rpx;
						width: 100%;
					}
				}
			}
		}

		.list-goods {
			background-color: #fff;
			padding: 20rpx;
			border-radius: 10rpx;

			.total {
				margin-top: 20rpx;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 24rpx;
				text-align: left;
				color: #666;
				white-space: nowrap;

				text {
					margin-right: 20rpx;
				}
			}

			.item {
				padding: 10rpx 0;
				border-bottom: 2rpx solid #eee;

				.img {
					width: 112rpx;
					height: 180rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.con {
					flex: 1;
					padding: 0 20rpx;
					width: 1rpx;

					.title {
						font-size: 28rpx;
						color: #333;
					}

					.tips {

						text {
							color: #999;
							font-size: 24rpx;
							margin: 10rpx 10rpx 0 0;
						}
					}
				}

				.r {
					text-align: right;

					.price {
						font-size: 24rpx;
						color: #666;
						height: 60rpx;
						line-height: 60rpx;
					}

					.num {
						font-size: 24rpx;
						color: #666;
					}
				}
			}
		}

		.m-title {
			height: 80rpx;
			line-height: 80rpx;
			color: #333;
			font-size: 32rpx;

			text {
				margin-left: 10rpx;
				font-size: 24rpx;
				color: @color;
			}
		}

		.main {
			background-color: #fff;
			padding: 20rpx;
			border-radius: 10rpx;

			.p {
				line-height: 40rpx;
				font-size: 24rpx;
				color: #333;

				text {
					width: 150rpx;
					margin-right: 30rpx;
				}
			}
		}
	}
</style>